package com.baitiaojun.elasticsearch.api.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.baitiaojun.api.vo.JsonRes;
import com.baitiaojun.api.vo.PageInfo;
import com.baitiaojun.elasticsearch.api.FullTextSearchApi;
import com.baitiaojun.elasticsearch.handler.GlobalDegradeHandler;
import com.baitiaojun.elasticsearch.service.FullTextSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @类名 FullTextSearchApiImpl
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/1/5 13:27
 * @版本 1.0
 */
@RestController
public class FullTextSearchApiImpl implements FullTextSearchApi {

    @Autowired
    private FullTextSearchService fullTextSearchService;

    @SentinelResource(
            value = "fullTextSearch"
            , blockHandler = "defaultExHandler"
            , blockHandlerClass = GlobalDegradeHandler.class
    )
    @Override
    public JsonRes fullTextSearch(String keyword, Integer pageNo, Integer pageSize) throws IOException {
        PageInfo pageInfo = fullTextSearchService.searchContent(keyword, pageNo, pageSize);
        return JsonRes.builder().data(pageInfo);
    }
}
